var url="";
var model;
var request;
var Comment;
var result =false;
var result1=false;
var result2=false;
//'http://'+url+'/app/IndustryEnergyEval!ajaxPieChart'
//'http://'+url+'/app/IndustryEnergyEval!ajaxBarChart'
function LoadData(){
   result = false;
   result1=false;
   result2=false;
   LoadPieData();
   LoadBarData();
}

function  LoadPieData(){
    request.post('http://'+url+'/app/AreaEnergyEval!ajaxPieChart').success(function(data){
        // if(data!=null&&data.length==0){
        //    $("#body").html("<div style='margin:100px auto;width:200px;height:100px;position: relative;text-align:center;'><img  style='position: relative;' src='image/nodata.png' width='62' height='66'/><br/><span style='font-size:14px;color:rgb(141,141,141);'>没有相关内容!</span></div>");
        //  }else
        //  {
        //  }
       model.list = data;  
       option.series[0].data.length=0;
      for(var i=0;i<data.length;i++)
      {
        var obj = new Object();
         obj.value = data[i].value;
         obj.name = data[i].value;
         option.series[0].data.push(obj);
      }
      //转化成百分比显示
       option.series[0].data = model.calutepercent(option.series[0].data);
       console.log(option.series[0].data);
       LoadPie();
       result1=true;
       if(result1&&result2)   result=true;
         }).error(function(data,status,headers,config){
      if((status>=200&&status<300)||status===304||status===1223||status===0){
      $("body").html("网络访问出错！");
      }
      });
}

function LoadBarData(){
      request.post('http://'+url+'/app/AreaEnergyEval!ajaxBarChart').success(function(data){

         console.log(data);
         model.calp(data);
        result2=true;
       if(result1&&result2)   result=true;
         }).error(function(data,status,headers,config){
      if((status>=200&&status<300)||status===304||status===1223||status===0){
      $("body").html("网络访问出错！");
      }
      });
}

(function(){
	var app=angular.module('Comment',[ ]);



	app.controller('CommentController',['$http','$window',function($http,$window){
     Comment=this;
     url ="120.26.110.125/jncloud";
		request=$http;
    model=Comment;
    bindEvent();
    LoadData();
    Comment.barlist=new Array();

    Comment.calutepercent=function(list){
      if(list!=null)
      {
        sum=0;
        for(var i=0;i<list.length;i++)
        {
           sum+=parseFloat(list[i].value);
        }
        for(var i=0;i<list.length;i++)
        {
          list[i].name = ((list[i].value/sum*100).toFixed(2)+"%");
        }
      }
      return list;
    }

  Comment.calp=function(data){


   var sum = 0;
   Comment.barlist.length=0;
      for(var i=0;i<data.seriesData.length;i++)
      {
        var obj = new Object();
        obj.name = data.xAxisData[i];
        obj.value = data.seriesData[i];
         sum+= Number(data.seriesData[i]);
        obj.style = {'width':'65%'};
        Comment.barlist.push(obj);
      }
           console.log(Comment.barlist);

      for(var i=0;i<data.seriesData.length;i++)
      {
        var a = 65*parseInt(data.seriesData[i])/parseInt(sum);

         Comment.barlist[i].style.left=(a+'%');
         Comment.barlist[i].style.width=((100-a)+'%');
      }

     
  }
	}]);
})();
